import { onMounted, reactive, ref } from 'vue';
import { RouterLink } from 'vue-router';
import FeedingModal from '../widgets/FeedingModal.vue';
import DiaperModal from '../widgets/DiaperModal.vue';
import SleepModal from '../widgets/SleepModal.vue';
import CryModal from '../widgets/CryModal.vue';
import { recordsByDate, timelineByDate } from '../services/api';
const modals = reactive({ feeding: false, diaper: false, sleep: false, cry: false });
const openFeeding = () => (modals.feeding = true);
const openDiaper = () => (modals.diaper = true);
const openSleep = () => (modals.sleep = true);
const openCry = () => (modals.cry = true);
const lastFeeding = ref('--');
const lastDiaper = ref('--');
const sleepState = ref('--');
const todayDate = new Date().toISOString().slice(0, 10);
const todayFormulaMl = ref(0);
const todayBreastMinutes = ref(0);
async function loadOverview() {
    const payload = { babyId: 1, date: todayDate };
    const data = await recordsByDate(payload);
    if (data.feedings?.length) {
        const f = data.feedings.sort((a, b) => b.eventTime.localeCompare(a.eventTime))[0];
        lastFeeding.value = f.feedingType === 'FORMULA'
            ? `${formatTime(f.eventTime)} / ${f.formulaMl ?? '-'}ml`
            : `${formatTime(f.eventTime)} / 左${f.leftMinutes ?? 0}分 右${f.rightMinutes ?? 0}分`;
    }
    else
        lastFeeding.value = '--';
    if (data.diapers?.length) {
        const d = data.diapers.sort((a, b) => b.eventTime.localeCompare(a.eventTime))[0];
        lastDiaper.value = `${formatTime(d.eventTime)}`;
    }
    else
        lastDiaper.value = '--';
    if (data.sleeps?.length) {
        const ongoing = data.sleeps.find((s) => !s.sleepEnd);
        sleepState.value = ongoing ? '睡觉中' : '清醒';
    }
    else
        sleepState.value = '清醒';
    // 统计今日总奶
    const feedings = Array.isArray(data.feedings) ? data.feedings : [];
    todayFormulaMl.value = feedings
        .filter((f) => f.feedingType === 'FORMULA')
        .reduce((sum, f) => sum + (Number(f.formulaMl) || 0), 0);
    todayBreastMinutes.value = feedings
        .filter((f) => f.feedingType === 'BREAST_MILK')
        .reduce((sum, f) => sum + (Number(f.leftMinutes) || 0) + (Number(f.rightMinutes) || 0), 0);
}
function formatTime(iso) { const d = new Date(iso); return d.toTimeString().slice(0, 5); }
const loadingTimeline = ref(false);
const timeline = ref([]);
function mapTypeText(t) {
    return t === 'FEEDING' ? '喂奶' : t === 'DIAPER' ? '尿布' : t === 'SLEEP' ? '睡眠' : '哭闹';
}
function summarize(i) {
    if (i.type === 'FEEDING') {
        const d = i.data;
        return d.feedingType === 'FORMULA' ? `${d.formulaMl ?? '-'}ml` : `母乳 左${d.leftMinutes ?? 0}分 右${d.rightMinutes ?? 0}分`;
    }
    if (i.type === 'DIAPER')
        return (i.data?.diaperType === 'WET' ? '清尿' : i.data?.diaperType === 'DIRTY' ? '便便' : '混合');
    if (i.type === 'SLEEP')
        return i.data?.sleepEnd ? '已醒' : '睡眠中';
    if (i.type === 'CRY')
        return '—';
    return '';
}
async function loadTimeline() {
    try {
        loadingTimeline.value = true;
        const payload = { babyId: 1, date: todayDate };
        const res = await timelineByDate(payload);
        timeline.value = Array.isArray(res) ? res : [];
    }
    finally {
        loadingTimeline.value = false;
    }
}
onMounted(() => { loadOverview(); loadTimeline(); });
debugger; /* PartiallyEnd: #3632/scriptSetup.vue */
const __VLS_ctx = {};
let __VLS_components;
let __VLS_directives;
// CSS variable injection 
// CSS variable injection end 
__VLS_asFunctionalElement(__VLS_intrinsicElements.div, __VLS_intrinsicElements.div)({
    ...{ class: "space-y-6" },
});
__VLS_asFunctionalElement(__VLS_intrinsicElements.div, __VLS_intrinsicElements.div)({
    ...{ class: "grid grid-cols-1 lg:grid-cols-3 gap-4" },
});
__VLS_asFunctionalElement(__VLS_intrinsicElements.div, __VLS_intrinsicElements.div)({
    ...{ class: "card col-span-2" },
});
__VLS_asFunctionalElement(__VLS_intrinsicElements.div, __VLS_intrinsicElements.div)({
    ...{ class: "flex items-center gap-4" },
});
__VLS_asFunctionalElement(__VLS_intrinsicElements.img)({
    ...{ class: "w-16 h-16 rounded-full object-cover" },
    src: "https://via.placeholder.com/100",
    alt: "baby",
});
__VLS_asFunctionalElement(__VLS_intrinsicElements.div, __VLS_intrinsicElements.div)({});
__VLS_asFunctionalElement(__VLS_intrinsicElements.div, __VLS_intrinsicElements.div)({
    ...{ class: "text-xl font-semibold" },
});
__VLS_asFunctionalElement(__VLS_intrinsicElements.div, __VLS_intrinsicElements.div)({
    ...{ class: "text-gray-500 text-sm" },
});
__VLS_asFunctionalElement(__VLS_intrinsicElements.div, __VLS_intrinsicElements.div)({
    ...{ class: "grid grid-cols-2 md:grid-cols-4 gap-3 mt-4 text-sm" },
});
__VLS_asFunctionalElement(__VLS_intrinsicElements.div, __VLS_intrinsicElements.div)({
    ...{ class: "p-3 rounded bg-bg" },
});
(__VLS_ctx.lastFeeding);
__VLS_asFunctionalElement(__VLS_intrinsicElements.div, __VLS_intrinsicElements.div)({
    ...{ class: "p-3 rounded bg-bg" },
});
(__VLS_ctx.lastDiaper);
__VLS_asFunctionalElement(__VLS_intrinsicElements.div, __VLS_intrinsicElements.div)({
    ...{ class: "p-3 rounded bg-bg" },
});
(__VLS_ctx.sleepState);
__VLS_asFunctionalElement(__VLS_intrinsicElements.div, __VLS_intrinsicElements.div)({
    ...{ class: "p-3 rounded bg-bg" },
});
(__VLS_ctx.todayFormulaMl);
(__VLS_ctx.todayBreastMinutes);
__VLS_asFunctionalElement(__VLS_intrinsicElements.div, __VLS_intrinsicElements.div)({
    ...{ class: "card" },
});
__VLS_asFunctionalElement(__VLS_intrinsicElements.div, __VLS_intrinsicElements.div)({
    ...{ class: "font-semibold mb-2" },
});
__VLS_asFunctionalElement(__VLS_intrinsicElements.div, __VLS_intrinsicElements.div)({
    ...{ class: "grid grid-cols-2 gap-3" },
});
__VLS_asFunctionalElement(__VLS_intrinsicElements.button, __VLS_intrinsicElements.button)({
    ...{ onClick: (__VLS_ctx.openFeeding) },
    ...{ class: "btn-primary" },
});
__VLS_asFunctionalElement(__VLS_intrinsicElements.button, __VLS_intrinsicElements.button)({
    ...{ onClick: (__VLS_ctx.openDiaper) },
    ...{ class: "btn-primary" },
});
__VLS_asFunctionalElement(__VLS_intrinsicElements.button, __VLS_intrinsicElements.button)({
    ...{ onClick: (__VLS_ctx.openSleep) },
    ...{ class: "btn-primary" },
});
__VLS_asFunctionalElement(__VLS_intrinsicElements.button, __VLS_intrinsicElements.button)({
    ...{ onClick: (__VLS_ctx.openCry) },
    ...{ class: "btn-primary" },
});
__VLS_asFunctionalElement(__VLS_intrinsicElements.div, __VLS_intrinsicElements.div)({
    ...{ class: "card" },
});
__VLS_asFunctionalElement(__VLS_intrinsicElements.div, __VLS_intrinsicElements.div)({
    ...{ class: "flex justify-between items-center mb-3" },
});
__VLS_asFunctionalElement(__VLS_intrinsicElements.div, __VLS_intrinsicElements.div)({
    ...{ class: "font-semibold" },
});
const __VLS_0 = {}.RouterLink;
/** @type {[typeof __VLS_components.RouterLink, typeof __VLS_components.RouterLink, ]} */ ;
// @ts-ignore
const __VLS_1 = __VLS_asFunctionalComponent(__VLS_0, new __VLS_0({
    to: "/timeline",
    ...{ class: "text-secondary" },
}));
const __VLS_2 = __VLS_1({
    to: "/timeline",
    ...{ class: "text-secondary" },
}, ...__VLS_functionalComponentArgsRest(__VLS_1));
__VLS_3.slots.default;
var __VLS_3;
if (__VLS_ctx.loadingTimeline) {
    __VLS_asFunctionalElement(__VLS_intrinsicElements.div, __VLS_intrinsicElements.div)({
        ...{ class: "text-sm text-gray-500" },
    });
}
else {
    __VLS_asFunctionalElement(__VLS_intrinsicElements.ul, __VLS_intrinsicElements.ul)({
        ...{ class: "space-y-2 text-sm" },
    });
    if (__VLS_ctx.timeline.length === 0) {
        __VLS_asFunctionalElement(__VLS_intrinsicElements.li, __VLS_intrinsicElements.li)({
            ...{ class: "p-2 rounded bg-bg text-gray-500" },
        });
    }
    for (const [it, idx] of __VLS_getVForSourceType((__VLS_ctx.timeline))) {
        __VLS_asFunctionalElement(__VLS_intrinsicElements.li, __VLS_intrinsicElements.li)({
            key: (idx),
            ...{ class: "p-2 rounded bg-bg" },
        });
        (__VLS_ctx.formatTime(it.eventTime));
        (__VLS_ctx.mapTypeText(it.type));
        (__VLS_ctx.summarize(it));
    }
}
/** @type {[typeof FeedingModal, ]} */ ;
// @ts-ignore
const __VLS_4 = __VLS_asFunctionalComponent(FeedingModal, new FeedingModal({
    open: (__VLS_ctx.modals.feeding),
}));
const __VLS_5 = __VLS_4({
    open: (__VLS_ctx.modals.feeding),
}, ...__VLS_functionalComponentArgsRest(__VLS_4));
/** @type {[typeof DiaperModal, ]} */ ;
// @ts-ignore
const __VLS_7 = __VLS_asFunctionalComponent(DiaperModal, new DiaperModal({
    open: (__VLS_ctx.modals.diaper),
}));
const __VLS_8 = __VLS_7({
    open: (__VLS_ctx.modals.diaper),
}, ...__VLS_functionalComponentArgsRest(__VLS_7));
/** @type {[typeof SleepModal, ]} */ ;
// @ts-ignore
const __VLS_10 = __VLS_asFunctionalComponent(SleepModal, new SleepModal({
    open: (__VLS_ctx.modals.sleep),
}));
const __VLS_11 = __VLS_10({
    open: (__VLS_ctx.modals.sleep),
}, ...__VLS_functionalComponentArgsRest(__VLS_10));
/** @type {[typeof CryModal, ]} */ ;
// @ts-ignore
const __VLS_13 = __VLS_asFunctionalComponent(CryModal, new CryModal({
    open: (__VLS_ctx.modals.cry),
}));
const __VLS_14 = __VLS_13({
    open: (__VLS_ctx.modals.cry),
}, ...__VLS_functionalComponentArgsRest(__VLS_13));
/** @type {__VLS_StyleScopedClasses['space-y-6']} */ ;
/** @type {__VLS_StyleScopedClasses['grid']} */ ;
/** @type {__VLS_StyleScopedClasses['grid-cols-1']} */ ;
/** @type {__VLS_StyleScopedClasses['lg:grid-cols-3']} */ ;
/** @type {__VLS_StyleScopedClasses['gap-4']} */ ;
/** @type {__VLS_StyleScopedClasses['card']} */ ;
/** @type {__VLS_StyleScopedClasses['col-span-2']} */ ;
/** @type {__VLS_StyleScopedClasses['flex']} */ ;
/** @type {__VLS_StyleScopedClasses['items-center']} */ ;
/** @type {__VLS_StyleScopedClasses['gap-4']} */ ;
/** @type {__VLS_StyleScopedClasses['w-16']} */ ;
/** @type {__VLS_StyleScopedClasses['h-16']} */ ;
/** @type {__VLS_StyleScopedClasses['rounded-full']} */ ;
/** @type {__VLS_StyleScopedClasses['object-cover']} */ ;
/** @type {__VLS_StyleScopedClasses['text-xl']} */ ;
/** @type {__VLS_StyleScopedClasses['font-semibold']} */ ;
/** @type {__VLS_StyleScopedClasses['text-gray-500']} */ ;
/** @type {__VLS_StyleScopedClasses['text-sm']} */ ;
/** @type {__VLS_StyleScopedClasses['grid']} */ ;
/** @type {__VLS_StyleScopedClasses['grid-cols-2']} */ ;
/** @type {__VLS_StyleScopedClasses['md:grid-cols-4']} */ ;
/** @type {__VLS_StyleScopedClasses['gap-3']} */ ;
/** @type {__VLS_StyleScopedClasses['mt-4']} */ ;
/** @type {__VLS_StyleScopedClasses['text-sm']} */ ;
/** @type {__VLS_StyleScopedClasses['p-3']} */ ;
/** @type {__VLS_StyleScopedClasses['rounded']} */ ;
/** @type {__VLS_StyleScopedClasses['bg-bg']} */ ;
/** @type {__VLS_StyleScopedClasses['p-3']} */ ;
/** @type {__VLS_StyleScopedClasses['rounded']} */ ;
/** @type {__VLS_StyleScopedClasses['bg-bg']} */ ;
/** @type {__VLS_StyleScopedClasses['p-3']} */ ;
/** @type {__VLS_StyleScopedClasses['rounded']} */ ;
/** @type {__VLS_StyleScopedClasses['bg-bg']} */ ;
/** @type {__VLS_StyleScopedClasses['p-3']} */ ;
/** @type {__VLS_StyleScopedClasses['rounded']} */ ;
/** @type {__VLS_StyleScopedClasses['bg-bg']} */ ;
/** @type {__VLS_StyleScopedClasses['card']} */ ;
/** @type {__VLS_StyleScopedClasses['font-semibold']} */ ;
/** @type {__VLS_StyleScopedClasses['mb-2']} */ ;
/** @type {__VLS_StyleScopedClasses['grid']} */ ;
/** @type {__VLS_StyleScopedClasses['grid-cols-2']} */ ;
/** @type {__VLS_StyleScopedClasses['gap-3']} */ ;
/** @type {__VLS_StyleScopedClasses['btn-primary']} */ ;
/** @type {__VLS_StyleScopedClasses['btn-primary']} */ ;
/** @type {__VLS_StyleScopedClasses['btn-primary']} */ ;
/** @type {__VLS_StyleScopedClasses['btn-primary']} */ ;
/** @type {__VLS_StyleScopedClasses['card']} */ ;
/** @type {__VLS_StyleScopedClasses['flex']} */ ;
/** @type {__VLS_StyleScopedClasses['justify-between']} */ ;
/** @type {__VLS_StyleScopedClasses['items-center']} */ ;
/** @type {__VLS_StyleScopedClasses['mb-3']} */ ;
/** @type {__VLS_StyleScopedClasses['font-semibold']} */ ;
/** @type {__VLS_StyleScopedClasses['text-secondary']} */ ;
/** @type {__VLS_StyleScopedClasses['text-sm']} */ ;
/** @type {__VLS_StyleScopedClasses['text-gray-500']} */ ;
/** @type {__VLS_StyleScopedClasses['space-y-2']} */ ;
/** @type {__VLS_StyleScopedClasses['text-sm']} */ ;
/** @type {__VLS_StyleScopedClasses['p-2']} */ ;
/** @type {__VLS_StyleScopedClasses['rounded']} */ ;
/** @type {__VLS_StyleScopedClasses['bg-bg']} */ ;
/** @type {__VLS_StyleScopedClasses['text-gray-500']} */ ;
/** @type {__VLS_StyleScopedClasses['p-2']} */ ;
/** @type {__VLS_StyleScopedClasses['rounded']} */ ;
/** @type {__VLS_StyleScopedClasses['bg-bg']} */ ;
var __VLS_dollars;
const __VLS_self = (await import('vue')).defineComponent({
    setup() {
        return {
            RouterLink: RouterLink,
            FeedingModal: FeedingModal,
            DiaperModal: DiaperModal,
            SleepModal: SleepModal,
            CryModal: CryModal,
            modals: modals,
            openFeeding: openFeeding,
            openDiaper: openDiaper,
            openSleep: openSleep,
            openCry: openCry,
            lastFeeding: lastFeeding,
            lastDiaper: lastDiaper,
            sleepState: sleepState,
            todayFormulaMl: todayFormulaMl,
            todayBreastMinutes: todayBreastMinutes,
            formatTime: formatTime,
            loadingTimeline: loadingTimeline,
            timeline: timeline,
            mapTypeText: mapTypeText,
            summarize: summarize,
        };
    },
});
export default (await import('vue')).defineComponent({
    setup() {
        return {};
    },
});
; /* PartiallyEnd: #4569/main.vue */
